package com.tuananh.radnom.service;

import java.util.ArrayList;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.listener.SimpleMessageListenerContainer;

import com.tuananh.radnom.model.NetNode;
import com.tuananh.radnom.service.config.impl.DiscoverService;
import com.tuananh.radnom.service.config.impl.NetIntService;
import com.tuananh.radnom.service.config.impl.NetNodeService;
import com.tuananh.radnom.service.discovery.impl.ActiveDiscoverd;
import com.tuananh.radnom.service.discovery.impl.PassiveDiscoverd;
import com.tuananh.radnom.service.monitor.impl.PollDaemon;
import sun.net.ftp.*;

public class Engine {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ApplicationContext context = new ClassPathXmlApplicationContext("spring-services.xml");
		NetNodeService nodeService = (NetNodeService) context.getBean("netNodeService");
		ArrayList<NetNode> listNode = nodeService.getAll();
		PollDaemon pollDaemon = context.getBean(PollDaemon.class);
		 ActiveDiscoverd discoverd = new ActiveDiscoverd();
		 discoverd.setDiscoverService(context.getBean(DiscoverService.class));
		 discoverd.setNetNodeService(context.getBean(NetNodeService.class));
		 discoverd.setNetIntService(context.getBean(NetIntService.class));
		 Thread thread1 = new Thread(discoverd);
		 thread1.start();
		 while(!discoverd.isStop()){
			 
		 }
		//
		 System.out.println("Begin passive");
		 PassiveDiscoverd passiveD = new PassiveDiscoverd();
		 passiveD.setDiscoverService(context.getBean(DiscoverService.class));
		 passiveD.setNetNodeService(context.getBean(NetNodeService.class));
		 passiveD.setNetIntService(context.getBean(NetIntService.class));
		 Thread thread = new Thread(passiveD);
		 thread.start();
//		 while (true)
//		 {
//		     try
//		     {
//		         Thread.sleep(10);
//		     }
//		     catch (Exception e)
//		     {
//		         e.printStackTrace();
//		     }
//		 }
	}

}
